#include "StdAfx.h"

#include "Point.h"

#include "Direction.h"

Direction::Direction(double x, double y, double z, bool isNormalized) : Point(x, y, z)
{
	if (!isNormalized)
		Normalize();
}

Direction::Direction(double x, double y, double z) : Point(x, y, z)
{
	Normalize();
}

Direction::Direction(const Point& p) : Point(p)
{
	Normalize();
}

Direction::Direction(const Direction& p) : Point(p)
{}

void Direction::Set(double x, double y, double z)
{
	::Point::Set(x, y, z);
}

Direction Direction::operator+ (const Point& p)
{
	return Direction (p.X + X, p.Y + Y, p.Z + Z);
}

Direction Direction::operator- (const Point& p)
{
	return Direction (p.X - X, p.Y - Y, p.Z - Z);
}

void Direction::Set(const Point& p)
{
	::Point::Set(p);
	Normalize();
}


void Direction::Set(const Direction& p)
{
	::Point::Set(p);
}

void Direction::operator+=(const Point& p)
{
	::Point::operator+=(p);
	Normalize();
}

void Direction::operator*=(double scalar)
{
	if (scalar < 0)
	{
		X = -X;
		Y = -Y;
		Z = -Z;
	}
}

Direction Direction::Reflection(const Direction& normal) const
{
	double scalarMulted = -2 * (normal.X * X + normal.Y * Y + normal.Z * Z);
	return Direction(X + scalarMulted * normal.X, Y + scalarMulted * normal.Y, Z + scalarMulted * normal.Z, true);
}

double Direction::Length() {return 1;}
double Direction::SquaredLength() {return 1;}
